package com.titaniume.java;

import com.sun.org.apache.xpath.internal.functions.FuncFloor;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 *@program: JavaSenior
 *@description:
 * 1.关于自定义泛型类，泛型接口
 *
 *@author: renfei.huang
 *@create: 2021-10-14 09:48
 */
public class GenericTest1 {

    @Test
    public  void test(){


        //如果定义了泛型类，实例化没有指明类的泛型，则任务泛型类型为Object类型
        //要求： 如果大家定义了类时带泛型的，建议在实例化时要指明泛型的类型。
        Order order = new Order();
        order.setOrderT("123");
        order.setOrderT("abc");

        //建议：实例化指明类的泛型
        Order<String> order1 = new Order<>("OrderAA",1001,"order单据号：AA");
        order1.setOrderT("order单据号：AA-1");

    }

    @Test
    public  void test2(){

        SubOrder sub1 = new SubOrder();
        //由于子类在继承带泛型的父类时，指明了泛型类型，则实例化子类对象时，不在需要泛型
        sub1.setOrderT(1111);



        SubOrder1<String> sub2 = new SubOrder1();
        sub2.setOrderT("order2...");

    }


    @Test
    public  void test3(){

        ArrayList<Integer> list1 = null;
        ArrayList<String> list2 = null;
        //泛型不同的引用不能互相赋值
//      list1 == list2;

        Person p1 = null;
        Person p2 = null;
        p1 = p2;
    }


    @Test
    public void test4(){

        Order<String> order = new Order();

        Integer [] arr =  new Integer[]{123,454,1};
        //在调用的时候确定泛型
        List<Integer> integers = order.copyFromArrayToTis(arr);
        System.out.println(integers);

        String [] arr1=  new String[]{"aa","bb"};
        List<String> srings = order.copyFromArrayToTis(arr1);
        System.out.println(srings);
    }




}
